<%@page import="dao.impl.UserDAOImpl"%>
<%@page import="bean.UserStatus"%>
<%@page import="bean.UserBean"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
	+ request.getServerName() + ":" + request.getServerPort()
	+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'adminUser.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link rel="stylesheet" href="<%=path%>/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet"
	href="<%=path%>/bootstrap/css/bootstrap-theme.min.css" />
<script src="<%=path%>/bootstrap/js/bootstrap.min.js"></script>
<style type="text/css">
#head hd {
	text-align: center;
}
</style>
<script type="text/javascript" src="<%=path%>/js/jquery.min.js"></script>
<script type="text/javascript">
	function upRow(Node) {
		var row = Node.parentNode.parentNode; // 修改行所在表格中的位置
		var col = row.cells;
		var suser = col[0].innerHTML;
		var url = "AdminUserServlet?task=update&date=" + new Date().getTime();
		var slock;
		alert(suser);
		if (Node.innerHTML == "帐号解冻") {
			slock = "0";
			confirm("确定解冻帐号？");
			Node.innerHTML = "冻结帐号";
			col[4].innerHTML="未冻结";
		} else {
			confirm("确定冻结帐号？");
			slock = "1";
			Node.innerHTML = "帐号解冻";
			col[4].innerHTML="已冻结";
		}
		$.ajax({
			type : "post",
			url : url,
			data : "suser=" + suser + "&slock=" + slock,
			dataType : "json",
			success : function(json) {
				alert(json);
			}
		});
		
	}
</script>
</head>

<body  style="margin-top: 30px">
	<div class="col-md-12">
		<%
			String ope = request.getParameter("ope");
			UserDAOImpl daoImpl = new UserDAOImpl();
			List<UserBean> allUser = new ArrayList<UserBean>();
			if (ope == null) {
				allUser = daoImpl.selectListBySlever("2");
			} else if ("query".equals(ope)) {
				String suser = request.getParameter("suser");
				String saddress = request.getParameter("saddress");
				allUser = daoImpl.selectUserQueryList(suser, saddress);
			}
		%>
		<div class="col-md-6">
			<form action="admin/loginUser.jsp?ope=query" method="post">
				用户名：<input type="text" name="suser"> 住址：<input type="text"
					name="saddress"> <input type="submit" value="查询">
			</form>
		</div>
		<div>
			<form>
				<table border="1" class="table table-hover">
					<tr id="head">
						<td>用户名</td>
						<td>真实姓名</td>
						<td>性别</td>
						<td>注册时间</td>
						<td>是否冻结</td>
						<td>操作</td>
					</tr>
					<%
						for (UserBean userBean : allUser) {
							UserStatus userStatus = daoImpl.selectStatus(userBean
									.getSuser());
					%>
					<tr>
						<td><%=userBean.getSuser()%></td>
						<td><%=userBean.getSname()%></td>
						<td><%=userBean.getSsex()%></td>
						<td><%=userStatus.getDregdate()%></td>
						<%
							if ("1".equals(userStatus.getSlock())) {
						%>
						<td>已冻结</td>
						<td><a href="javascript:;" onclick="upRow(this)">帐号解冻</a>&nbsp;<a
							href="AdminUserServlet?task=add&suser=<%=userBean.getSuser()%>">添加为管理员</a>&nbsp;<a
							href="AdminUserServlet?task=delete&suser=<%=userBean.getSuser()%>">删除</a></td>
						<%
							} else {
						%>
						<td>未冻结</td>
						<td><a href="javascript:;" onclick="upRow(this)">冻结帐号</a>&nbsp;<a
							href="AdminUserServlet?task=add&suser=<%=userBean.getSuser()%>">添加为管理员</a>&nbsp;<a
							href="AdminUserServlet?task=delete&suser=<%=userBean.getSuser()%>">删除</a></td>
						<%
							}
						%>
					</tr>
					<%
						}
					%>
				</table>
			</form>
		</div>

	</div>
</body>
</html>
